import matplotlib.pyplot as plt
import numpy as np

def plot_num_cdf(file_path):
	cdf_x = []
	cdf_y = []
	with open(file_path, 'r') as file:
	    for line in file.readlines():
	    	split = line.split()
	    	print split
	    	cdf_x.append(float(split[0]))
	    	cdf_y.append(float(split[-1]))

	plt.semilogx(cdf_x, cdf_y,'r', linewidth=1)

	# plot the CDF
	fs = 14
	plt.title('Web search workload', fontsize=fs)
	plt.xlabel('Flow Size(Bytes)', fontsize=fs)
	plt.ylabel('CDF', fontsize=fs)
	plt.xlim(0,10000000000)
	plt.ylim(0,1)
	plt.legend(loc=0, fontsize=fs)
	plt.grid()
	plt.show()

# realistic traffic
def plot_real_cdf(file_path):
	flow_size = []
	with open( file_path, 'r') as file:
	    for line in file.readlines():
	    	split = line.split()
	    	flow_size.append(float(split[-1]))   
	flow_size.sort()
	cdf_x = flow_size
	cdf_y = np.linspace(1 / len(flow_size), 1.0, len(flow_size))

	fs = 14
	plt.semilogx(cdf_x, cdf_y,'b', linewidth=2, markersize=4, label='Flow Size')
	plt.title('Web search workload', fontsize=fs)
	plt.xlabel('Flow Size(Bytes)', fontsize=fs)
	plt.ylabel('CDF', fontsize=fs)
	plt.xlim(0,10000000000)
	plt.ylim(0,1)
	plt.legend(loc=0, fontsize=fs)
	plt.grid()
	plt.show()

if __name__ == '__main__':
	plt.figure(1, figsize=(8,4), dpi=80)
	# plot_num_cdf ('DCTCP_CDF.txt')
	plot_real_cdf('../flows.txt')
